function config($stateProvider, $urlRouterProvider,$httpProvider){
	
	$stateProvider
		.state("login",{
			url			:"/login",
			templateUrl	:"modules/login/Login.tpl.html",
			controller	: LoginController
		})
		.state("signout",{
			url			:"/login",
			templateUrl	:"modules/login/Login.tpl.html",
			controller	: LoginController
		})
		.state("register",{
			url			:"/register",
			templateUrl	:"modules/register/Register.tpl.html",
			controller	: RegisterController
		})
		.state("home",{
			url			:"/home",
			templateUrl	:"modules/home/Home.tpl.html",
			controller	: HomeController
		})
		.state("home.dashboard",{
			url			:"/dashboard",
			templateUrl	:"modules/dashboard/Dashboard.tpl.html",
			controller	: DashboardController
		})
		.state("supplier",{
			url			:"/supplier",
			templateUrl	:"modules/supplier/Supplier.tpl.html",
			controller	: SupplierController
		})
		.state("supplier.machines",{
			url			:"/machines",
			templateUrl	:"modules/supplier/machines/Machines.tpl.html",
			controller	: MachinesController
		})
		.state("supplier.chemicals",{
			url			:"/chemicals",
			templateUrl	:"modules/supplier/chemicals/Chemicals.tpl.html",
			controller	: ChemicalsController
		})
		.state("supplier.toolsandconsumables",{
			url			:"/toolsandconsumables",
			templateUrl	:"modules/supplier/toolsandconsumables/ToolsAndConsumables.tpl.html",
			controller	: ToolsAndConsumablesController
		});
	
		//Registering interceptor for showing loading on each ajax request
		$httpProvider.interceptors.push('myHttpInterceptor');
	
}

angular.module('eEstimateApp',['ui.router', 'ngAnimate','ngResource','context.service','login','home','dashboard','rest.service','error.utils','ngCookies'])
	.config(config)
	.factory('myHttpInterceptor', function($q) {
	    return {
	      // optional method
	      'request': function(config) {
	        // do something on success
	    	$("#spinner").show();
	        return config;
	      },
	
	      // optional method
	     'requestError': function(rejection) {
	        // do something on error
	    	 $("#spinner").hide();
	      },
	
	
	
	      // optional method
	      'response': function(response) {
	        // do something on success
	    	  $("#spinner").hide();
	        return response;
	      },
	
	      // optional method
	     'responseError': function(rejection) {
	        // do something on error
	    	 $("#spinner").hide();
	      }
	    };
	})
	.run(['$state','loadContext','$cookies',function($state,loadContext,$cookies){
			var model = loadContext.loadContext();
			
			if(model == undefined){
				//re-route to login
				$state.go("login");
			}
			else{
				//re-route to home
				$state.go("home");
			}
	}]);